{extend name="public/base" /}
{block name="css"}
<style>
#info{display: none;}
.info_{color: red;text-align: center;line-height: 3;padding-left: 0px;padding-right: 0px;}
</style>
{/block}
{block name="container"}
<div class="panel panel-default">
    <div class="panel-heading">
        <h4 class="panel-title">会员卡充值</h4>
    </div>
    <div class="panel-body panel-body-nopadding">

        <form class="form-horizontal form-bordered" id="submitForm" action="" method="post" >
            <div class="form-group">
                <label class="col-sm-3 control-label">卡号:</label>
                <div class="col-sm-6">
                    <input type="text" class="form-control" name="card_num" id="card_num" placeholder="请输入卡号"  value="">
                </div>
            </div>
            <div class="form-group" id="info">

            </div>
            
            <div class="form-group">
                <label class="col-sm-3 control-label"><span>*</span>金额：</label>
                <div class="col-sm-6">
                    <input class="form-control" type="text" name="money" id="money" placeholder="请输入金额" datatype="*" value="" required >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label"><span>*</span>赠送金额：</label>
                <div class="col-sm-6">
                    <input class="form-control" type="text" name="song_money" id="song_money" placeholder="请输入金额" datatype="*" value="" required >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label"><span>*</span>积分：</label>
                <div class="col-sm-6">
                    <input class="form-control" type="text" name="jifen" id="jifen" placeholder="请输入金额" datatype="*" value="" required >
                </div>
            </div>
            <div class="panel-footer">
                <div class="row">
                    <div class="col-sm-6 col-sm-offset-3">
                        <input type="hidden" name="id" value="">
                        <button type="submit" class="btn btn-primary">提交</button>
                        <button type="button" class="btn btn-default" onclick="javascript:history.back(-1);">返回</button>
                    </div>
                </div>
            </div><!-- panel-footer -->

        </form>
    </div>
    {/block}
    {block name="js"}
    <script>
        $(function() {
            $("[name='status'][value='{$data.status ?? '1'}']").attr("checked", true);
            $("[name='sex'][value='{$data.sex ?? '1'}']").attr("checked", true);
            $('#money').change(function() {
                var num  = $('#money').val();
                document.getElementById('song_money').value = num;
                document.getElementById('jifen').value = num;
            });
            $('#card_num').keydown(function(event) {
                if(event.keyCode == '13')
                {
                    $.post('{:url("index/member/getMemberInfo")}', {card_num: $('#card_num').val()}, function(data) {
                        /*optional stuff to do after success */
                        if(data.sta ==1)/*正常用户*/
                        {
                            $('#info').append(`<label class="col-sm-3 control-label">信息：</label>
                                <div class="col-sm-6" >
                                <span class="col-sm-1  info_">姓名：</span>
                                <span class="col-sm-1  info_">`+data['name']+`</span>
                                <span class="col-sm-1  info_">余额：</span>
                                <span class="col-sm-1  info_">`+data['money']+`</span>
                                <span class="col-sm-1  info_">状态：</span>
                                <span class="col-sm-1  info_">正常</span>
                                <span class="col-sm-2  info_">办卡时间：</span>
                                <span class="col-sm-2  info_">`+data['add_time']+`</span>
                                </div>`);
                            $('#info').css('display','block');    
                     }else if(data.sta == 2)
                     {
                        swal({title: '该卡已被冻结',text: "",type: "error"});
                        document.getElementById('card_num').value = '' ; 
                    }else{
                        swal({title: '该卡号不存在',  text: "",type: "error"});
                        document.getElementById('card_num').value = '' ;
                    }

                });
                    return false;
                }
            });
        });
    </script>
    {/block}